C/C++ Working Directory in Visual Studio
Email from Steve 3/11/2024
For C/C++ solution Debugging sessions the default directory is the directory containing the project file (*.vcxproj) for the solution’s startup project. When specifying file paths as command line arguments on the debug properties page this is the root directory (. Directory) for relative paths.
For example, if there was a input file (input.dat) in a subdirectory input of that project’s directory, you could specify it as a input argument using the following construct .\input\input.dat instead of using the it’s full absolute path.
Output file whose names do not contain directory paths will also be written to the solution’s “startup project” project directory. i.e. an output file opened using the filename output.out will appears as the file output.out in the directory containing the project file for the solution’s startup project.
When committing solutions to GitHub, if you what to include sample input files, using paths relative to the startup project will allow other who down load the solution to run it without needing to reset file paths.
I have yet not checked to determine if this convention also holds for other project types in VS2022.